﻿
using Common;
using Common.Communications;
using Common.Model;
using Newtonsoft.Json;
using OpticalComService.Services;
using OpticalService;
using RcsService;
using System.Text;

namespace OpticalComService
{
    public class OpticalHostedService : BackgroundService
    {
      
        protected async override Task ExecuteAsync(CancellationToken token)
        {
            ReadSettingInfo();
            OpticalInitService.Instance.ServiceInitProcess();
        }

        /// <summary>
        /// 读取配置文件内容
        /// </summary>
        private void ReadSettingInfo()
        {
            AppSetting.Instance.ReadMultipleSubInfo<OpticalServiceModel>(ConstString.OpticalServiceKey);
            AppSetting.Instance.ReadMultipleSubInfo<ProtocolModel>(ConstString.ProtocalRcsKey);
            //读取Rcs服务的ip和端口数据
            List<string> subKey = new List<string>();
            subKey.Add(ConstString.SettSubKeyIp);
            subKey.Add(ConstString.SettSubKeyPort);
            RcsServiceSettingModel instance = new RcsServiceSettingModel();
            AppSetting.Instance.ReadSingleSubInfo(ConstString.RcsServiceKey, subKey, instance);
            //读取当前设备的编号
            StringBuilder eqCode = new StringBuilder();
            AppSetting.Instance.ReadSingleSubInfo(ConstString.EquipmentNumberKey,null, eqCode);
            //读取滚筒通信参数
            List<string> subKeyRoller = new List<string>();
            subKeyRoller.Add(ConstString.SettSubKeyIp);
            subKeyRoller.Add(ConstString.SettSubKeyPort);
            RollerSettingModel instanceRoller = new RollerSettingModel();
            AppSetting.Instance.ReadSingleSubInfo(ConstString.RollerControlKey, subKeyRoller, instanceRoller);


            AppSetting.Instance.GetEquipMentCodeSettingInfo();
        }
    }
}
